package cn.flyingroc.travelbook;

import cn.flyingroc.travelbook.util.DatabaseHelper;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {
	
	Context context;
	private static final String TAG = "Splash";
	private SQLiteDatabase sqliteDatabase;
	private DatabaseHelper databaseHelper;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		context = getApplicationContext();
		
		/*判断存储卡是否存在*/
        if(!checkSDCard()){
        	Main.mMakeTextToast(context,getResources().getText(R.string.errNoSD_bottom_new_poi).toString(),true);
        }
		
        //检查数据库表
        this.open(context);
        
		Handler x = new Handler();
		x.postDelayed(new splashhandler(), 1000);
	}
	
	private boolean checkSDCard(){
		if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
			return true;
		}else{
			return false;
		}
	}
	
	class splashhandler implements Runnable{
		
        public void run() {
            startActivity(new Intent(getApplication(),Main.class));
            Splash.this.finish();
        }
        
    }
	
	/** 
     * 打开数据库连接 
     */
    public void open(Context context)
    {
        databaseHelper = new DatabaseHelper(context);
        
        try
        {
            sqliteDatabase = databaseHelper.getWritableDatabase();
        }catch(SQLiteException ex)
        {
            sqliteDatabase = databaseHelper.getReadableDatabase();
        }
        databaseHelper.onCreate(sqliteDatabase);
    }

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}
	
	
	
}
